package hibernateDAOS;

import hibernate.HibernateUtil;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import beans.TareaElaboracion;


public class TareaElaboracionDAO 
{
	private static TareaElaboracionDAO instancia = null;
	private static SessionFactory sf = null;
	
	public static TareaElaboracionDAO getInstancia()
	{
		if(instancia == null)
		{
			sf = HibernateUtil.getSessionFactory();
			instancia = new TareaElaboracionDAO();
		} 
		return instancia;
	}
	
	
	public  void guardarTareaElaboracion(TareaElaboracion te){
		Session session = sf.openSession();
		session.beginTransaction();
		session.save(te);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}
	
	public void eliminarTareaElaboracion(TareaElaboracion te){
		Session session = sf.openSession();
		session.beginTransaction();
		session.delete(te);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void modificarTareaElaboracion(TareaElaboracion te){
		Session session = sf.openSession();
		session.beginTransaction();
		session.saveOrUpdate(te);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	@SuppressWarnings("unchecked")
	public List<TareaElaboracion> obtenerTareasElaboracion()
	{
		Session session = sf.openSession();
		Query q = session.createQuery("from TareaElaboracion");
		List<TareaElaboracion> compras = q.list();
		session.close();
		return compras;
	}
}
